﻿@{
    ViewBag.Title = "LikeMenu";
    Layout = "~/Views/Shared/_LayoutPageAll.cshtml";
}
<script src="~/js/jquery-1.8.2.js"></script>
<script>

    $(function () {
        $.ajax({
            type: "get", //访问WebService使用Post方式请求

            url: "http://localhost:19451/api/Menu/getshow", //调用WebService

            success: function (response) { //回调函数，result，返回值
                //alert(response)
                var tr = "";

                $(response).each(function (i, item) {

                    if (item.MenuId % 2 == 0)
                    {
                        tr += "<div  class='right-part'><h4><span class='text'>" + item.MenuName + "</span><span class='line'></span></h4><ul><li><div class='img-holder'><div class='canvas'></div><img typeof='foaf:Image' src='" + item.MenuPhoto + "' width='108' height'90' alt='' /></div><div class='price'><h5><a href='/product/convallis-sit-amet-tellus'>" + item.MenuName + "</a></h5><span>$" + item.MenuPrice + "</span></div><div class='description'><p>" + item.MenuDescrib + "</p></div><div class='form-actions form-wrapper' id='edit-actions--2'><input class='node-add-to-cart form-submit' type='submit' id='edit-submit-3' name='op' value='加入购物车'onclick='fun(" + item.MenuId + ")' /></div></li></ul></div>"
                    }
                    else
                    {
                        tr += "<div  class='left-part' ><h4><span class='text'>" + item.MenuName + "</span><span class='line'></span></h4><ul><li><div class='img-holder'><div class='canvas'></div><img typeof='foaf:Image' src='" + item.MenuPhoto + "' width='108' height'90' alt='' /></div><div class='price'><h5><a href='/product/convallis-sit-amet-tellus'>" + item.MenuName + "</a></h5><span>$" + item.MenuPrice + "</span></div><div class='description'><p>" + item.MenuDescrib + "</p></div><div class='form-actions form-wrapper' id='edit-actions--2'><input class='node-add-to-cart form-submit' type='submit' id='edit-submit-3' name='op' value='加入购物车'onclick='fun(" + item.MenuId + ")' /></div></li></ul></div>"
                    }

                  //tr += "<tr><td>" + item.MenuName + "</td><td><img  src='" + item.MenuPhoto + "' style='width:120px;height:90px;'/></td><td>" + item.MenuDescrib + "</td><td>" + item.MenuPrice + "</td></tr>"


                }

)
                $("#dd").append(tr);
            }

        });

    })

    function fun(n)
    {
        var id=@Session["UserID"];
        $.ajax({
            type:'get',
            url:'http://localhost:19451/api/menu/GetMenuIdshow',
            data:{
                id:n,
            },
            success:function(data){
                if(data==""){
                    alert("");
                }
                else
                {
                    var arr=JSON.parse(data);
                    $(arr).each(function(i,obj){
                          $.ajax({
                            type: "Get", //访问WebService使用Post方式请求
                            url: "http://localhost:19451/api/menu/getaddcar",
                            data:{
                                CarId:obj.MenuId,
                                CarName:obj.MenuName,
                                CarPhoto:obj.MenuPhoto,
                                CarDescrib:obj.MenuDescrib,
                                CarPrice:obj.MenuPrice,
                                CarNum:1,
                                UserId:id,
                            },
                            success: function (response) { //回调函数，result，返回值


                                if(response==1)
                                {
                                    alert('添加成功');
                                }
                                else if(response==2)
                                {
                                    alert('添加成功');
                                }
                                else
                                {
                                    alert('没有此菜品');
                                }
                            }
                        })

                    })


                }
            }
        })

    }

</script>
<a href="/Home/Shopping">我的订单</a>
@*页面中心内容*@
<div class="content clearfix">
    <div class="breadcrumbs">
        <h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="/">返回主页</a> » 菜&nbsp;&nbsp;&nbsp;单 </div>
    </div>

    <div id="content" class="column content-inner">
        <div class="section">
            <a id="main-content"></a>
            <div class="region region-content">
                <div id="block-system-main" class="block block-system">
                    <div class="content">
                        <div class="product-menu-header">
                            <h2>Menu</h2>
                        </div>

                        <div class="product-menu-holder">

                            <div id="dd">
                                @Html.Raw(ViewBag.LikeMenu)
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>




